#include "sqlite3.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

int call_back(void *, int, char **, char **);

int main(int argc, char *argv[])
{
    sqlite3 *db_p;
    sqlite3_open("./student.db", &db_p);

    char create_table_buf[] = "create table if not exists student(\
                student_id integer primary key ,\
                student_name text,\
                student_age integer);\
        ";

    char *msg = NULL;
    sqlite3_exec(db_p, create_table_buf, NULL, NULL, &msg);
    if (msg != NULL)
        printf("%s\n", msg);

    char show_table[] = "select student_name from student where student_id like 123";
    sqlite3_exec(db_p, show_table, call_back, NULL,&msg);
    if (msg != NULL)
        printf("%s\n", msg);

    sqlite3_close(db_p);
    return 0;
}

int call_back(void *p, int num_of_col, char **text, char **name)
{
    for (int i = 0; i < num_of_col; i++)
    {
        printf(" %s" , text[i]);
    }
    printf("\n");
    return 0;
}
